<template>
	<view class="container">
		<view class="" v-if="menuList.length">
			<uni-list v-for="(item,index) in menuList" :key="index">
				<!-- 头像显示角标 -->
				<uni-list-chat :avatar-circle="true" @click="detail(item)" :title="item.title||'--'"
					:avatar="item.img" :note="item.messageContent||'--'" :time="item.createTime||'--'"
					badge-positon="left" badge-text="dot" link>
				</uni-list-chat>
			</uni-list>
			<uni-load-more :status="status" @clickLoadMore="clickLoadMore" :contentText="contentText" />
		</view>
		<view class="no-data" v-else style="text-align: center;">
			<image src="../../static/icons/nodata.png" style="width: 150rpx;" mode="widthFix"></image>
			<text>暂无消息列表数据</text>
		</view>

	</view>
</template>

<script>
	import {
		toast,
		useRouter,
		signOut,
		getStorageSync
	} from '../../utils/utils.js'
	import {
		message
	} from '../../api/msg.js'
	export default {
		data() {
			return {
				status: 'more',
				contentText: {
					contentdown: '上拉加载更多',
					contentrefresh: '加载中',
					contentnomore: '~别拉了，到底了~'
				},
				menuList: [],
				messageParams: {
					pageNum: 1,
					pageSize: 10
				}
			};
		},
		onShow() {
			// uni.setTabBarBadge({
			//   index: 1,
			//   text: '100'
			// })
		},
		onTabItemTap() {
			const token = getStorageSync('token') || null

			if (!token) {

				signOut()
				toast('请先登录后在使用!')
			}
		},
		onLoad() {
			this.messageInquire()
		},
		onReachBottom() {
			this.status = 'loading'
			this.messageParams.pageNum ++
			this.messageInquire()

		},
		onPullDownRefresh() {

			this.messageParams.pageNum = 1
			this.messageInquire()
		},
		methods: {
			detail(item) {

				useRouter('/pages/message/detail', JSON.stringify({
					noticeId: item.messageLoggingId
				}), 'navigateTo')
			},
			messageInquire() {
				message(this.messageParams).then(res => {
					
					if (!res.rows.length) {
						this.status = 'no-more'
					} else {
						this.status = 'more'
					}
					res.rows.forEach((item, index) => {
						// var messageQuery={
						// 	type: item.noticeTitle?item.noticeTitle:'无标题',
						// 	img: '../../static/icons/tongzhi.png',
						// 	time:item.createTime?item.createTime:'无创建时间',
						// 	content:item.noticeContent?item.noticeContent:'无内容',
						// 	createBy:item.createBy?item.createBy:'无创建人'
						// }
						this.menuList.push({
							...item,
							img: '../../static/icons/tongzhi.png',
						})

					})
					uni.stopPullDownRefresh();

				})
			}
		}
	}
</script>

<style lang="scss" >
	.no-data {
		position: absolute;
		top: 0rpx;
		left: 0;
		right: 0;
		bottom: 0;
		color: #333333;
		width: 100%;
		z-index: 1;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
	}
</style>